package worldinruin.gui.imp.gameview;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import worldinruin.core.ITroop;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SelectedTroopsPanel extends javax.swing.JPanel {

	ArrayList<ITroop> troops = new ArrayList<ITroop>();
	
	/**
	 * Creates a selected troops panel.
	 * @param arg Troop to display on panel.
	 */
	public SelectedTroopsPanel(ArrayList<ITroop> arg) {
		super();
		this.troops = arg;
		initGUI(arg);
		updateGUI(arg);
	}

	/**
	 * Initializes the GUI.
	 * @param troops Sets the GUI up depending on the troop.
	 */
	private void initGUI(ArrayList<ITroop> troops) {
		try {
			GridLayout thisLayout = new GridLayout(troops.size(), 1);
			thisLayout.setColumns(1);
			thisLayout.setHgap(5);
			thisLayout.setVgap(5);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(400, 300));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Updates the GUI.
	 * @param troops New troop values to adapt GUI to.
	 */
	private void updateGUI(List<ITroop> troops) {
		removeAll();
		for (ITroop t : troops) {
			JPanel troopPanel = new TroopPanel(t);
			this.add(troopPanel);
		}
	}
}
